/*
 * Copyright 2007 Rob Nielsen
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.googlecode.proxymatic.core;

import java.lang.reflect.Method;

/**
 * MethodHandler is the base interface for handlers.  MethodHandlers should be stateless and immutable. A call to
 * getInvoker with the same method and context should return an equivalent MethodInvoker every time. As much as possible
 * should be done in the getInvoker method (in terms of locating the appropriate method to invoke in the
 * implementationClasses) so that the MethodInvoker should be as simple as possible.
 */
public interface MethodHandler {
    // FIX ROB Is there some way to return a reason why we couldn't find a match?  This may help to provide
    // better error messages
    MethodInvoker NOT_HANDLED = null;

    /**
     * @param method       the target method to be invoked
     * @param context      the buildtime context to be used to determine how to handle the method
     * @param proxyBuilder the proxybuilder used to create the method.  This can be used to create more proxy objects,
     *                     if required by the application.
     * @return a method invoker for this method, or NOT_HANDLED if this handler does not support the method.
     */
    public MethodInvoker getInvoker(Method method, BuildtimeContext context, ProxyBuilder proxyBuilder);
}
